<#import "../common/common.ftl" as common />
<@common.page>
	<!-- Classes -->
	<!-- ux	-->
	<script type="text/javascript" src="${res}/js/ext/ux/Ext.ux.MonthPickerPlugin.js"></script>
	
	<script type="text/javascript">
		peanut.NewestProblemQuery = Ext.extend(Ext.Panel, {
		    width: '100%',
		    height: '100%',
		    renderTo:null,
		    gridViewConfig: {},
		    pageSize: EXT_PAGE_SIZE,
			baseUrl: AJAX_ROOT_URL+"/dataquality/queryNewestProblemMonth",
		    cm: new Ext.grid.CellSelectionModel(),
		    sm: new Ext.grid.RowSelectionModel({
				dataIndex: this.ID
			}),//-列选择模式
		    store1: null,
		    storeMapping: ["comcode","comcname","wrongcnt"],
		    
		    grid1:null,
		    
		    //表单元素
		    row1: {
				layout:'column',
				bodyStyle:'border-width:0;',
				items:[{
					columnWidth:.5,
		            layout:'form',
		            bodyStyle:'border-width:0;',
		            //baseCls:'x-plain',
		            items:[{
		            	id:'month',
		            	xtype:'datefield',
		                plugins:'monthPickerPlugin',
		            	format:'Y-m',
		            	width:120,
		            	labelStyle:'text-align:right;',
		            	editable: false,
		                fieldLabel:'月份',
		                value: new Date().add(Date.MONTH, -1)
		            }]
				},{
					columnWidth:.5,
		            layout:'form',
		            bodyStyle:'border-width:0;',
		            //baseCls:'x-plain',
		            items:[{
		            	id:'product',
		            	xtype:'combo',
		            	labelStyle:'text-align:right;',
		            	editable:false,
		                fieldLabel:'产品线',
		                mode:'local',
		                triggerAction:'all',
    					//lazyRender:true,
    					//blankText: '----',
    					//emptyText: '----',
					    store: new Ext.data.Store({
					    	autoLoad:true,
	                        url: AJAX_ROOT_URL+'/dataquality/queryProduct',
				            reader: new Ext.data.JsonReader({}, ['departcode', 'departname']),
				            listeners:{
					    		'load':function(store,record,opts) {
					    			Ext.getCmp("product").setValue(store.data.items[0].data.departcode);
				    			}
					    	}
				        }),
					    valueField: 'departcode',
					    displayField: 'departname'
		            }]
				}]
		    },
		    row2:{
		    	layout:'column',
				bodyStyle:'border-width:0;',
				items:[{
					columnWidth:.7,
		            layout:'form',
		            bodyStyle:'border-width:0;',
		            //baseCls:'x-plain',
		            items:[{
		            	id:'region',
		            	xtype:'textfield',
		            	labelStyle:'text-align:right;',
		            	editable:false,
		                fieldLabel:'组织机构'
	                }]
                }]
		    },
		    row3: {
				layout:'column',
				bodyStyle:'border-width:0;',
				items:[{
					columnWidth:.3,
		            layout:'form',
		            bodyStyle:'border-width:0;',
		            //baseCls:'x-plain',
		            items:[{
		            	id:'province',
		            	xtype:'combo',
		            	editable:false,
		            	labelStyle:'text-align:right;',
		                fieldLabel:'省',
		                mode:'local',
		                triggerAction:'all',
    					//lazyRender:true,
    					forceSelection:true,
    					allowBlank: false,
    					//autoSelect:true,  //本地才有用
    					lazyInit:false,
					    store: new Ext.data.Store({
					    	autoLoad:true,
	                        url: AJAX_ROOT_URL+'/dataquality/queryProvince',
				            reader: new Ext.data.JsonReader({}, ['comcode', 'comcname']),
				            listeners:{
					    		'load':function(store,record,opts) {
					    			Ext.getCmp("province").setValue(store.data.items[0].data.comcode);
					    			Ext.getCmp("city").store.removeAll();
					    			Ext.getCmp("city").store.load({
					    				params:{
					    					province:Ext.getCmp("province").getValue()
					    				}
					    			});
					    		},
					    		'change':function(field,newValue,oldValue ) {
					    			Ext.getCmp("city").store.removeAll();
					    			Ext.getCmp("city").store.load({
					    				params:{
					    					province:newValue
					    				}
					    			});
					    		}
				            }
				        }),
					    valueField: 'comcode',
					    displayField: 'comcname'
		            }]
				},{
					columnWidth:.3,  
		            layout:'form',
		            bodyStyle:'border-width:0;',
		            items:[{
		            	id:'city',
		            	xtype:'combo',
		            	editable:false,
		            	labelStyle:'text-align:right;',
		                fieldLabel:'市',
		                mode:'local',
		                triggerAction:'all',
		                width:'100%',
					    store: new Ext.data.Store({
	                        url: AJAX_ROOT_URL+'/dataquality/queryCity',  
				            reader: new Ext.data.JsonReader({}, ['comcode', 'comcname']),
				            listeners:{
					    		'load':function(store,record,opts) {
					    			Ext.getCmp("city").setValue(store.data.items[0].data.comcode);
					    		}
				            }
				        }),
					    valueField: 'comcode',
					    displayField: 'comcname'
		            }]
				},{
					columnWidth:.3,  
		            layout:'form',
		            bodyStyle:'border-width:0;',
		            //baseCls:'x-plain',
		            items:[{
		            	id:'county',
		            	xtype:'combo',  
		            	editable:false,
		            	labelStyle:'text-align:right;',
		                fieldLabel:'县' 
		            }]
				}]
		    },
		 
		    //构造器
		    constructor: function(config){
		        config = config || {};
		        this.pageSize = config.pageSize || EXT_PAGE_SIZE;
		        
		        var viewConfig = Ext.apply({
		            forceFit: true
		        }, this.gridViewConfig);
		        
		        if(this.view){
		            Ext.apply(this.gridPanel,{
		                view: this.view
		            });
		        };
		        
		        this.cm.defaultSortable = true;
		        
		        this.cm = new Ext.grid.ColumnModel([
		            new Ext.grid.RowNumberer(),//获得行号
				    //this.sm,
				    {
				        header:"公司代码",
				        dataIndex:"comcode",
				        align:'center',
				        style:'font-weight:bold;',
				        //可以进行排序
		                sortable:true
			        },{
				        header:"公司名称",
				        dataIndex:"comcname",
				        align:'center',
		                sortable:true,
		                style:'font-weight:bold;'
			        },{
				        header:"问题笔数",
				        width:80,
				        style:'font-weight:bold;',
				        align:'center',
				        dataIndex:"wrongcnt",
		                sortable:true
			        }
			    ]);
		        
		        this.store1 = new Ext.data.JsonStore({
	                id: this.ID,
	                url: this.baseUrl,
	                root: EXT_STORE_ROOT,
	                totalProperty: EXT_STORE_TOTALPROPERTY,
	                remoteSort: true,
	                fields: this.storeMapping
	            })
		        
		        this.grid1 = new Ext.grid.GridPanel({
		            id:Ext.id(),
		            store:this.store1,
		            cm:this.cm,
		            sm:this.sm,
		            autoHeight:true,
		            //height:600,
		            trackMouseOver:false,
		            labelStyle:'font-weight:bold;',
		            anchor:'100%',
		            loadMask: true,
		            //超过长度带自动滚动条
				    autoScroll:true,
				    border:false,
				    //collapsible: true,
		            animCollapse:false,
		            viewConfig:{
		            	forceFit: true
		            },
		            listeners: {
		                //'celldblclick': {//双击时执行修改
		                    //fn: this.onEdit,
		                    //scope: this
		                //},
		                'contextmenu':function(e) {
		                    e.stopEvent();
		                },
		                'cellcontextmenu':function(Grid,Rindex,Cindex,E){
					    }
		            },
		            //tbar:config.fp,
		            //分页
		            bbar: new Ext.PagingToolbar({
		                pageSize: this.pageSize,
		                store: this.store1,
		                buttonAlign:'right'
		            })
		        });
		        
		        this.store1.load({
		            params: {
		                start: 0,
		                limit: this.pageSize
		            }
		        });
		        
		        var configs = Ext.apply({
		            closable: true,
		            autoScroll: true,
		            layout: "anchor",
		            items:[
		            	new Ext.form.FormPanel({
					    	plain:true,
					    	frame:true,
					    	bodyStyle:'border-width:0;height:95.5%;width:100%',
							layout:"form",
							//defaultType:"textfield",
							labelWidth:75,
					        //baseCls:"x-plain",
							//defaults:{anchor:"30%",msgTarget:"side"},
							anchor:'100%',
							autoHeight:true,
							buttonAlign:"right",
							labelAlign:"center",
							//bodyStyle:"padding:10 10 10 10",
					    	items:[this.row1, this.row2],
					    	buttons:[{
					    		text:'查询',
					    		handler: this.onSearch,
					    		scope:this
					    	}]
					    }), 
					    new Ext.TabPanel({
					    	activeTab: 0,
					    	items:[{
					    		title:'公司维度', 
					    		autoHeight:true,    
				               	autoWidth:true,    
				               	autoScroll:true,    
				              	frame:true, 
					    		items:this.grid1
				    		}, {
				    			title:'产品线维度', 
				    			height:'100%'
			    			}]
					    })
				    ],
		            /**
		              *渲染数据
		              */
		            //链接
		            linkRenderer: function(v){
		                if (!v) 
		                    return "";
		                else 
		                    return String.format("<a href='{0}' target='_blank'>{0}</a>", v);
		            },
		            //时间
		            dateRender: function(format){
		                format = format || "Y-m-d h:i";
		                return Ext.util.Format.dateRenderer(format);
		            }
		        },config);
		        //调用父类的构造器
		        peanut.NewestProblemQuery.superclass.constructor.call(this,configs);
		    },
		       
		    /**
		      *事件
		      */
		    //刷新
		    onRefresh: function(){
		        this.store1.removeAll();
		        this.store1.reload();
		    }
		});

		
		Ext.onReady(function(){
			var reportQuery = new peanut.NewestProblemQuery({
				//header:false,
				renderTo:Ext.getBody()
			});
		});
	</script>
	</head>
<body style="background-color:transparent">
</body>
</@common.page>